/**
 * 基础实体接口
 */
export interface BaseEntity {
  id: string;
  createdAt: Date;
  updatedAt: Date;
  deletedAt?: Date;
}

/**
 * 用户接口
 */
export interface IUser extends BaseEntity {
  username: string;
  email: string;
  password: string;
  firstName: string;
  lastName: string;
  phone?: string;
  avatar?: string;
  bio?: string;
  dateOfBirth?: Date;
  gender?: 'male' | 'female' | 'other' | 'prefer_not_to_say';
  location?: string;
  website?: string;
  role: 'admin' | 'user' | 'moderator' | 'guest';
  status: 'active' | 'inactive' | 'suspended' | 'pending' | 'deleted';
  emailVerified: boolean;
  emailVerificationToken?: string;
  emailVerificationExpires?: Date;
  passwordResetToken?: string;
  passwordResetExpires?: Date;
  lastLoginAt?: Date;
  loginAttempts: number;
  lockUntil?: Date;
}

/**
 * 订单接口
 */
export interface IOrder extends BaseEntity {
  orderNumber: string;
  userId: string;
  items: Array<{
    itemId: string;
    name: string;
    price: number;
    quantity: number;
    sku: string;
  }>;
  subtotal: number;
  tax: number;
  shipping: number;
  discount: number;
  total: number;
  currency: string;
  status: 'pending' | 'confirmed' | 'processing' | 'shipped' | 'delivered' | 'cancelled' | 'refunded';
  paymentStatus: 'pending' | 'processing' | 'completed' | 'failed' | 'cancelled' | 'refunded';
  paymentMethod: string;
  shippingAddress: {
    street: string;
    city: string;
    state: string;
    postalCode: string;
    country: string;
  };
  billingAddress: {
    street: string;
    city: string;
    state: string;
    postalCode: string;
    country: string;
  };
  trackingNumber?: string;
  estimatedDelivery?: Date;
  deliveredAt?: Date;
  notes?: string;
}

/**
 * 类别接口
 */
export interface ICategory extends BaseEntity {
  name: string;
  slug: string;
  description?: string;
  parentId?: string;
  image?: string;
  level: number;
  sortOrder: number;
  status: 'active' | 'inactive';
  metadata?: Record<string, unknown>;
}

/**
 * 文章接口
 */
export interface IArticle extends BaseEntity {
  title: string;
  slug: string;
  content: string;
  excerpt?: string;
  authorId: string;
  categoryId?: string;
  featuredImage?: string;
  images?: string[];
  tags: string[];
  status: 'draft' | 'published' | 'archived';
  publishedAt?: Date;
  views: number;
  likes: number;
  seoData?: {
    title: string;
    description: string;
    keywords: string[];
  };
  metadata?: Record<string, unknown>;
}

/**
 * 评论接口
 */
export interface IComment extends BaseEntity {
  content: string;
  authorId: string;
  targetType: 'article' | 'comment';
  targetId: string;
  parentId?: string;
  rating?: number;
  status: 'pending' | 'approved' | 'rejected';
  likes: number;
  metadata?: Record<string, unknown>;
}

/**
 * 文件接口
 */
export interface IFile extends BaseEntity {
  originalName: string;
  fileName: string;
  path: string;
  url: string;
  mimeType: string;
  size: number;
  extension: string;
  uploadedBy: string;
  description?: string;
  tags?: string[];
  isPublic: boolean;
  metadata?: Record<string, unknown>;
}

/**
 * 设置接口
 */
export interface ISetting extends BaseEntity {
  key: string;
  value: unknown;
  type: 'string' | 'number' | 'boolean' | 'object' | 'array';
  category: string;
  description?: string;
  isPublic: boolean;
  isEditable: boolean;
}

/**
 * 日志接口
 */
export interface ILog extends BaseEntity {
  level: 'error' | 'warn' | 'info' | 'debug';
  message: string;
  meta?: Record<string, unknown>;
  userId?: string;
  ip?: string;
  userAgent?: string;
  endpoint?: string;
  method?: string;
  statusCode?: number;
  responseTime?: number;
  stack?: string;
}

/**
 * 会话接口
 */
export interface ISession extends BaseEntity {
  userId: string;
  token: string;
  refreshToken?: string;
  expiresAt: Date;
  lastAccessAt: Date;
  ip: string;
  userAgent: string;
  isActive: boolean;
  metadata?: Record<string, unknown>;
}

/**
 * 分页查询参数接口
 */
export interface PaginationQuery {
  page: number;
  limit: number;
  sortBy?: string;
  sortOrder?: 'asc' | 'desc';
  keyword?: string;
}

/**
 * 分页查询结果接口
 */
export interface PaginatedResult<T> {
  data: T[];
  pagination: {
    page: number;
    limit: number;
    total: number;
    totalPages: number;
    hasNext: boolean;
    hasPrev: boolean;
  };
}

/**
 * 查询过滤器接口
 */
export interface QueryFilter {
  [key: string]: unknown;
}

/**
 * 查询选项接口
 */
export interface QueryOptions {
  select?: string[];
  populate?: string | string[];
  lean?: boolean;
  sort?: Record<string, 1 | -1>;
  skip?: number;
  limit?: number;
}

/**
 * 统计数据接口
 */
export interface IStats {
  users: {
    total: number;
    active: number;
    inactive: number;
    newThisMonth: number;
  };
  products: {
    total: number;
    active: number;
    outOfStock: number;
    lowStock: number;
  };
  orders: {
    total: number;
    pending: number;
    completed: number;
    cancelled: number;
    totalRevenue: number;
    revenueThisMonth: number;
  };
  traffic: {
    totalViews: number;
    uniqueVisitors: number;
    bounceRate: number;
    avgSessionDuration: number;
  };
}